<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;
use think\facade\View;
use think\response\Json;

class ProductCate extends Base
{
    protected string $pk = 'id';

    protected string $model = '\app\common\model\ProductCate';

    protected string $validate = 'ProductCate';

    public function index(): string
    {
        View::assign('list', $this->model::getAll());

        return View::fetch();
    }

    public function edit($id = '', $pid = '', $tpl = 'product_cate/edit'): string
    {
        $p_title = '';
        if ($pid) {
            $p_title = $this->model::where('id', $pid)->value('title');
        }
        View::assign('p_title', $p_title);
        View::assign('form', ['title' => '图标', 'field' => 'icon', 'value' => 1]);

        return parent::edit($id, $tpl);
    }

    public function getCate(): Json
    {
        $id = $this->request->param('id', 0);

        return json($this->model::getCate($id));
    }
}